package net.dodoman.excel;

import java.io.BufferedWriter;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileWriter;
import java.io.IOException;
import java.util.List;

public class BatWriter {
	private static final String PREFIX = "sde2shp -o init -l ";

	private static final String MIDDLE_1 = ",shape -f ";
	private static final String MIDDLE_2 = " -t ";
	private static final String SUFFIX = " -a all -s 172.25.2.86 -i esri_sde -u py_ytt_sde -p py_ytt_sde_augur";

	private static final String ARC_FLAG = "_L";

	private static final String POLYGON_FLAG = "_R";

	private static final String POINT_FLAG = "_P";

	private static final String ARC_TYPE = "arc";

	private static final String POLYGON_TYPE = "polygon";

	private static final String POINT_TYPE = "point";

	private static final String SPLIT_KEY = "PY_YTT_SDE.";

	// 生成导出批处理文件路径
	private static final String BAT_FILE_PATH = "D:/gonganzhengli/10000_dx/10000_gz/2shape_gn.bat";

	// sde2shp -o init -l PY_YTT_SDE.Py01Bou06GGZ_BOULIN_L,shape -f b -t arc -a
	// all -s 172.25.2.86 -i esri_sde -u py_ytt_sde -p py_ytt_sde_augur

	public static void generateBat(List<String> list) {
		try {
			File write = new File(BAT_FILE_PATH);
			BufferedWriter bw = new BufferedWriter(new FileWriter(write));
			for (String temp : list)
				bw.write(PREFIX + SPLIT_KEY + temp + MIDDLE_1 + temp + MIDDLE_2
						+ getType(temp) + SUFFIX + "\n");
			bw.close();
		} catch (FileNotFoundException e) { // 文件未找到
			System.out.println(e);
		} catch (IOException e) {
			System.out.println(e);
		}
	}

	private static String getType(String s) {
		String stemp = s.substring(s.length() - 2, s.length());
		if (stemp.equals(ARC_FLAG))
			return ARC_TYPE;
		else if (stemp.equals(POLYGON_FLAG))
			return POLYGON_TYPE;
		else if (stemp.equals(POINT_FLAG))
			return POINT_TYPE;
		return null;
	}
}
